#!/usr/bin/perl 
use DBI;
use CGI;
use TTraker;
use strict;

& print_header;
& initialize_dbi;

my $form_ref = parse_input();
my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $task = $FORM_DATA{'taskID'};
my $desc = $FORM_DATA{'description'};
my $units = $FORM_DATA{'units'};
my $stdMin= $FORM_DATA{'stdMin'};
my $whs= $FORM_DATA{'show_whs'};
my $csr= $FORM_DATA{'show_csr'};
my $admin= $FORM_DATA{'show_adm'};
my $in =  $FORM_DATA{'inbound'};
my $out =  $FORM_DATA{'outbound'};
my $msg = ""; 
my @checked = ();

my $errlev = 0;
if ( $task eq "" || $desc eq "" || $units eq "" || $stdMin eq "") {
	$msg = "TaskID, Description, Units and Standard Minutes must all have values!<br/>";
	$errlev ++; 
}
if ( $csr eq "" && $whs eq "" && $admin eq "" ) {
	$msg = "$msg" . "Must show task to at least one of WHS, CSR and ADMIN!<br/>";
	$errlev ++; 
}	
if ( $in eq "" && $out eq "") {
	$msg = "$msg" . "Task must be Inbound, Outbound or both!<br/>";
	$errlev ++; 
}	

if ($errlev == 0) {
	adm_add_new_master_task_details ($task, $desc, $units, $stdMin, $whs, $csr, $admin, $in, $out);
	$msg = "New Master Task added: $task"; 
	adm_activity_screen_from_pm ($num, $name, $job, $loc, $msg);
} else {
	if ( $whs eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	if ( $csr eq "on" ) { push @checked, "CHECKED";	} else { push @checked, ""; }
	if ( $admin eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	if ( $in eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	if ( $out eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
#	refresh_adm_add_master_task_detailed_screen_message ($task, $desc, $units, $stdMin, $whs, $csr, $admin, $in, $out);
	my $chkd = \@checked;
	& refresh_adm_add_master_task_detailed_screen_message ($num, $name, $job, $loc, $task, $desc, $units, $stdMin, $whs, $csr, $admin, $in, $out, $msg, $chkd);
}	

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################


sub refresh_adm_add_master_task_detailed_screen_message
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
my $task = $_[4];
my $desc = $_[5];
my $units = $_[6];
my $stdMin = $_[7];
my $whs = $_[8];
my $csr = $_[9];
my $admin = $_[10];
my $in = $_[11];
my $out = $_[12];
my $msg = $_[13];
my $chkd = $_[14];
my @checked = @$chkd;

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_03 adm_client_task_detail_screen</title>
</head>
<body>
<h2><center>${banner}</center></h2>
<hr/>
<div id='box5_1'>
<h3>New Master Task: $task</h3>
<div id='box1_4'>
Description:<br/><br/>
Units:<br/><br/>
Standard Min:<br/><br/>
</div>
<form autocomplete='off' name='startJob' action='${cgi_ref}trak_04_adm_add_master_task.pl' method='post'>
<div id='box2_1'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<input type="hidden" name=taskID value='$task'/>
<input type="text" name=description size="48"><br/><br/>
<input type="text" name=units size="8"><br/><br/>
<input type="text" name=stdMin size="8"><br/><br/>
</div>
<div id='box1_5'>
Show on the following lists:
<br/><br/>
<label><input type=checkbox name=show_whs>&nbsp&nbsp&nbsp WHS</label>
<label><input type=checkbox name=show_csr>&nbsp&nbsp&nbsp CSR</label>
<label><input type=checkbox name=show_adm>&nbsp&nbsp&nbsp ADMIN</label>
<br/><br/>
<label><input type=checkbox name=inbound>&nbsp&nbsp&nbsp Inbound</label>
<label><input type=checkbox name=outbound>&nbsp&nbsp&nbsp Outbound</label>
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
<br/><br/>
</div>


</form>
</body>
</html>

ENDHEADER

}

